package android.activity;

import java.util.List;

import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.app.ListActivity;

import android.adapters.BankAdapter;
import android.content.Intent;
import android.loaders.FunLoader;
import android.loaders.ILoader;
import android.model.BankItem;

/*
 * ne e komentirana zatoa sto ja vrsi istata funkcija kako i Bank.java
 * samo prikazuva razlicni podatoci
 */

public class Fun extends ListActivity {
	
	ILoader<BankItem> funLoader;
	BankAdapter funAdapter;

	private final void populateList() {
		try {
			List<BankItem> list = funLoader.load();
			if (funAdapter == null) {
				funAdapter = new BankAdapter(this, list);
				setListAdapter(funAdapter);
			} else {
				funAdapter.clear();
				for (BankItem listText : list) {
					funAdapter.add(listText);
				}
			}
			funAdapter.notifyDataSetChanged();
		} catch (Exception e) {
		}
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		funLoader = new FunLoader(this);
	}

	@Override
	protected void onResume() {
		super.onResume();
		populateList();
	}
	
	public void showFunDialogue()
	{
		Intent bankDialogueIntent=new Intent(this,android.activity.FunDialogue.class);
		startActivity(bankDialogueIntent);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		
		super.onCreateOptionsMenu(menu);
    	
    	menu.add(0, 0, 0, "Back");
    	menu.add(0, 1, 1, "Dialogues");
    	return true;	
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		
		switch(item.getItemId())
    	{
    	case 0:
    		finish();
    		return true;
    	case 1:
    		finish();
    		showFunDialogue();
    		return true;	
    	}
    	return true;
	}
	
	

}
